<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>提交修改</title>
    <meta name="renderer" content="webkit">
    <link rel="icon" href="/static/img/logo.jpg">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <!--    layui的组件和样式-->
    <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}" media="all">
    <script type="text/javascript" th:src="@{/static/layui/layui.js}"></script>

    <link rel="stylesheet" th:href="@{/static/lib/editormd/css/editormd.min.css}"/>
    <script th:src="@{/static/js/jquery-3.4.1.min.js}"></script>
    <script th:src="@{/static/lib/editormd/editormd.min.js}"></script>
</head>
<body>

<form id="submit" class="layui-form layui-form-pane" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">文件名</label>
        <div class="layui-input-inline">
            <input type="text" name="username" lay-verify="required" placeholder="请输入" autocomplete="off"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">日期选择</label>
            <div class="layui-input-block">
                <input type="text" name="date" id="date1" autocomplete="off" class="layui-input">
            </div>
        </div>

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-inline">
            <input type="password" name="password" lay-verify="required" placeholder="请输入密码" autocomplete="off"
                   class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">请务必填写用户名</div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">文件类型</label>
        <div class="layui-input-inline">
            <select name="interest" lay-filter="aihao">
                <option value=""></option>
                <option value=".md" selected="">.md</option>
                <option value=".txt">.txt</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <button id="myBtn"  class="layui-btn layui-hide" lay-submit="" lay-filter="demo2">跳转式提交</button>
    </div>
</form>


<script>

    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

        //自定义验证规则
        form.verify({
            title: function (value) {
                if (value.length < 5) {
                    return '标题至少得5个字符啊';
                }
            }
            , pass: [
                /^[\S]{6,12}$/
                , '密码必须6到12位，且不能出现空格'
            ]
        });
        form.on('submit(demo2)', function (data) {
            // console.log(data.field);
            window.parent.postMessage(JSON.stringify(data.field), '*');
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });
</script>

</body>
</html>